# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>

pkgname=qt6-tools
_qtver=6.6.0
pkgver=${_qtver/-/}
pkgrel=1
arch=(loong64 x86_64)
url='https://www.qt.io'
license=(GPL3 LGPL3 FDL custom)
pkgdesc='A cross-platform application and UI framework (Development Tools, QtHelp)'
depends=(gcc-libs
         glibc
         qt6-base
         zstd)
makedepends=(clang
             cmake
             llvm
             ninja
             qt6-declarative)
           # litehtml
optdepends=('clang: for qdoc and lupdate'
            'qt6-declarative: for qdoc and lupdate')
          # 'litehtml: for assistant'
groups=(qt6)
_pkgfn=${pkgname/6-/}-everywhere-src-$_qtver
source=(https://download.qt.io/official_releases/qt/${pkgver%.*}/$_qtver/submodules/$_pkgfn.tar.xz
        zstd-target.patch
        qt6-tools-fix-build.patch)
sha256sums=('4e9feebc142bbb6e453e1dc3277e09ec45c8ef081b5ee2a029e6684b5905ba99'
            '876b46461670d21b07d0e6a2ea53311d3c16be9e6fc3746f52b74e687f4eac8b'
            '8cced47330d1fed71e10248b4c587c0bac1cf6245b8149d2166d95de55b7cef8')

prepare() {
# Fix build with system litehtml
  sed -e '/qt_internal_set_exceptions_flags/d' -e '/qt_disable_warnings/d' -i $_pkgfn/src/assistant/CMakeLists.txt
# https://bugreports.qt.io/browse/QTBUG-117145
  patch -d $_pkgfn -p1 < zstd-target.patch
  patch -d $_pkgfn -p1 -i $srcdir/qt6-tools-fix-build.patch
}

build() {
  cmake -B build -S $_pkgfn -G Ninja \
    -DINSTALL_PUBLICBINDIR=usr/bin \
    -DCMAKE_MESSAGE_LOG_LEVEL=STATUS
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build

# Install symlinks for user-facing tools
  cd "$pkgdir"
  mkdir usr/bin
  while read _line; do
    ln -s $_line
  done < "$srcdir"/build/user_facing_tool_links.txt

  install -d "$pkgdir"/usr/share/licenses
  ln -s /usr/share/licenses/qt6-base "$pkgdir"/usr/share/licenses/$pkgname
}
